package com.bee.beemanage.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bee.beemanage.system.common.annotation.RedisCacheReload;
import com.bee.beemanage.api.entity.SysUser;
import com.bee.beemanage.api.mapper.SysUserMapper;
import com.bee.beemanage.api.service.SysUserService;
import com.bee.beemanage.system.common.utils.files.OSSUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author 陈国松
 * @since 2022-10-09
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    @Resource
    SysUserMapper sysUserMapper;
    @Resource
    private OSSUtil ossUtil;

    @Override
    public SysUser findUserByUserName(String userName) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>();
        queryWrapper.eq("username",userName);
        return sysUserMapper.selectOne(queryWrapper);
    }

    @Override
    @RedisCacheReload(keyName = "test")
    public void CacheTest() {

    }

    @Override
    public Page<SysUser> recycleSearch(Page<SysUser> page, SysUser sysUser,LocalDateTime startTime,LocalDateTime endTime) {
        return sysUserMapper.recycleSearch(page,sysUser,startTime,endTime);
    }

    @Override
    public boolean clear() {
        List<SysUser> sysUsers = sysUserMapper.deletedSearch();
        for (SysUser sysUser : sysUsers) {
            ossUtil.deleteFile(sysUser.getAvatar());
        }
        return sysUserMapper.clear();
    }

    @Override
    public boolean recover(List<String> ids) {
        return sysUserMapper.recover(ids);
    }
}
